home *** CD-ROM | disk | FTP | other *** search
/ Wayzata's Best of Shareware PC/Windows 1 / Wayzata's Best of Shareware for PC-Windows - Release 1 - Wayzata Technology (1993).iso / mac / DOS / GRAPHICS / RAYSH386 / VECTOR.H < prev    next >
C/C++ Source or Header  |  1991-07-18  |  2KB  |  91 lines

  1. /*
  2.  * vector.h
  3.  *
  4.  * Copyright (C) 1989, 1991, Craig E. Kolb
  5.  * All rights reserved.
  6.  *
  7.  * This software may be freely copied, modified, and redistributed
  8.  * provided that this copyright notice is preserved on all copies.
  9.  *
  10.  * You may not distribute this software, in whole or in part, as part of
  11.  * any commercial product without the express consent of the authors.
  12.  *
  13.  * There is no warranty or other guarantee of fitness of this software
  14.  * for any purpose.  It is provided solely "as is".
  15.  *
  16.  * $Id: vector.h,v 4.0 91/07/17 14:33:11 kolb Exp Locker: kolb $
  17.  *
  18.  * $Log:    vector.h,v $
  19.  * Revision 4.0  91/07/17  14:33:11  kolb
  20.  * Initial version.
  21.  * 
  22.  */
  23. #ifndef VECTOR_H
  24. #define VECTOR_H
  25. /*
  26.  * Constants used in projecting onto planes
  27.  */
  28. #define XNORMAL        (char)0
  29. #define YNORMAL        (char)1
  30. #define ZNORMAL        (char)2
  31.  
  32. /*
  33.  * Minimum vector length
  34.  */
  35. #define EPSILON        (Float)0.00001
  36. /*
  37.  * Maximum length
  38.  */
  39. #define FAR_AWAY        1.0E+14
  40.  
  41. typedef struct {
  42.     Float u, v;            /* 2D point */
  43. } Vec2d;
  44.  
  45. typedef struct Vector {
  46.     Float x, y, z;            /* 3D point */
  47. } Vector;
  48.  
  49. /*
  50.  * Linked list of points
  51.  */
  52. typedef struct PointList {
  53.     Vector    vec;            /* Vector data */
  54.     struct    PointList *next;    /* Next in list */
  55. } PointList;
  56.  
  57. /*
  58.  * Project a point in 3-space to the plane whose normal is indicated by "i."
  59.  */
  60. #define VecProject(r, p, i)    {switch(i) { \
  61.                 case XNORMAL: \
  62.                     r.u = (p).y; \
  63.                     r.v = (p).z; \
  64.                     break; \
  65.                 case YNORMAL: \
  66.                     r.u = (p).x; \
  67.                     r.v = (p).z; \
  68.                     break; \
  69.                 case ZNORMAL: \
  70.                     r.u = (p).x; \
  71.                     r.v = (p).y; \
  72.                     break; \
  73.                   } }
  74.  
  75. #define dotp(a, b)    (((a)->x*(b)->x)+((a)->y*(b)->y)+((a)->z*(b)->z))
  76. #define VecSub(a,b,r) (r)->x=(a).x-(b).x,(r)->y=(a).y-(b).y,(r)->z=(a).z-(b).z
  77. #define VecAdd(a,b,r) (r)->x=(a).x+(b).x,(r)->y=(a).y+(b).y,(r)->z=(a).z+(b).z
  78. #define VecScale(s,a,r)  (r)->x=(s)*(a).x,(r)->y=(s)*(a).y,(r)->z=(s)*(a).z
  79. #define VecComb(s1,v1,s2,v2,r)    (r)->x = (s1)*(v1).x + (s2)*(v2).x, \
  80.                  (r)->y = (s1)*(v1).y + (s2)*(v2).y, \
  81.                  (r)->z = (s1)*(v1).z + (s2)*(v2).z
  82. #define VecAddScaled(v1,s,v2,r)    (r)->x = (v1).x + (s)*(v2).x, \
  83.                  (r)->y = (v1).y + (s)*(v2).y, \
  84.                  (r)->z = (v1).z + (s)*(v2).z
  85.  
  86. extern void    VecCross(), VecCoordSys(), MakeBump();
  87. extern Float    VecNormCross(), VecNormalize();
  88. extern int    Refract();
  89.  
  90. #endif /* VECTOR_H */
  91.